package svc

import (
	"auth/internal/config"
	"auth/middleware"
	"github.com/zeromicro/go-zero/rest"
)

type ServiceContext struct {
	Config        config.Config
	JwtMiddleware rest.Middleware
}

func NewServiceContext(c config.Config) *ServiceContext {
	return &ServiceContext{
		Config:        c,
		JwtMiddleware: middleware.NewJwtMiddleware(c.Auth.AccessSecret).Handle,
	}
}

// RegisterMiddleware 注册全局中间件
func RegisterMiddleware(server *rest.Server, c config.Config) {
	jwtMiddleware := middleware.NewJwtMiddleware(c.Auth.AccessSecret).Handle
	server.Use(jwtMiddleware) // 全局注册 JWT 中间件
}
